/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.senai.config;

import br.com.senai.entities.Usuario;
import java.awt.Color;
import java.awt.Image;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.List;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;

/**
 *
 * @author Hugo
 */
public final class Config {

    public static final String NOME_SISTEMA = "Sistema de pães ";

    public static Usuario u = new Usuario();

    public static final Image LOGO_SISTEMA = new ImageIcon(Config.class.getClass().getResource("/br/com/senai/images/breads-icon.png")).getImage();

    public static final Color corFundo = Color.WHITE;

    public static String usuario = "";

    public static String senha = "";

    public static String url = "";
    
    public static final String email="hugohbpereira@gmail.com";
    
    public static final  String senhaEmail ="hajava10naveia";
    

    public static void carregarConexao() {

        List<String> linhas;
        try {
            linhas = Files.readAllLines(Paths.get("config.txt"), StandardCharsets.UTF_8);
        } catch (IOException ex) {
            linhas = null;
        }

        for (String a : linhas) {

            String[] split = a.split(";");
           usuario = split[0];
            url = split[1];
            senha = split[2];

        }
    }

    public static String criptograrSenha(char[] senha) {

        try {
            MessageDigest algorithm = MessageDigest.getInstance("SHA-256");
            byte messageDigest[] = algorithm.digest(new String(senha).getBytes("UTF-8"));

            StringBuilder hexString = new StringBuilder();
            for (byte b : messageDigest) {
                hexString.append(String.format("%02X", 0xFF & b));
            }
            return hexString.toString();
        } catch (NoSuchAlgorithmException | UnsupportedEncodingException e) {

            JOptionPane.showMessageDialog(null, "Erro ao configurar senha!", "Erro", JOptionPane.ERROR_MESSAGE);
            return "";
        }

    }

    public void mensagemSalvo() {
        JOptionPane.showMessageDialog(null, "Salvo.");
    }

}
